export default {
  data () {
    return {
      loading: false,
      pager: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        sizeChange: (val) => {
          this.pager.pageSize = val
          this.pager.currentPage = 1
          this.getData()
        },
        currentChange: (val) => {
          this.pager.currentPage = val
          this.getData()
        }
      },
      searchForm: {},
      tableData: []
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    async getData () {
      const queryParams = { ...this.searchForm, limit: this.pager.pageSize, offset: (this.pager.currentPage - 1) * this.pager.pageSize }
      this.loading = true
      const result = await this.list(queryParams)
      this.tableData = result.data.list
      this.loading = false
      this.pager.total = result.data.total
      this.pager.currentPage = result.data.currentPage
    },
    courseExpire (value) {
      return value > 0 ? `${value}天` : '永久'
    },
    onSearch () {
      this.pager.currentPage = 1
      this.getData()
    }
  }
}
